new Vue({
    el:'#productManage',
    data:{
        pageInfo:'',
        name:'',
        creationDate:'',
        infoFlag:false,
        infoText:'',
        styleObj:{
            backgroundColor:"#ff4e00",
            border:"none",
            height:"23px",
            width:"23px",
            color:"white"
        },
        no_bgc:{
            height:"22px",
            width:"22px",
        },
    },
    methods:{
        getProductPage(pageNum,pageSize)
        {
            axios.get('/api/admin/getProductPage',
                {
                    params:{
                        pageNum,
                        pageSize,
                        name:this.name,
                        creationDate:this.creationDate
                    }
                }).then(rs=>{
                    this.pageInfo=rs.data.pageInfo
            })
        },
        opera(sign)
        {
            let pageNum=1
            switch(sign)
            {
                case "pre":
                    pageNum=this.pageInfo.hasPreviousPage?this.pageInfo.prePage:1
                    break;
                case "next":
                    pageNum=this.pageInfo.hasNextPage?this.pageInfo.nextPage:this.pageInfo.pages
                    break;
                case "last":
                    pageNum=this.pageInfo.pages
                    break;
            }
            this.getProductPage(pageNum,5)
        },
        deleteProduct(id)
        {
            if(confirm("确认删除？"))
            {
                axios.get('/api/admin/deleteProduct',
                    {
                        params:{
                            id
                        }
                    }).then(rs=>{
                        this.infoFlag=true
                        if(rs.data.isDelete==="yes")
                        {
                            this.infoText="删除成功"
                            setTimeout(()=>{
                                window.location="/api/ProductManage.html"
                            },1000)
                        }else{
                            this.infoText="删除失败"
                        }
                })
            }
        },

        updateProduct(id)
        {
            window.location=`/api/updateProduct.html?id=${id}`
        },
        closeInfo()
        {
            this.infoFlag=false
        },
        goAddProduct()
        {
            window.location='/api/addProduct.html'
        }
    },
    created()
    {
        this.getProductPage(1,5)

    }
})